package com.ldl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.ldl.dao.LdlArticleDao;
import com.ldl.entity.LdlArticle;
import com.ldl.util.DBHelper;

/**
 * @author Administrator
 * Author : L.D.L
 * E-mail : 1419485293@qq.com
 * Date : 2020年7月25日下午3:45:40
 */
public class LdlArticleDaoImpl implements LdlArticleDao{

	/* (non-Javadoc)
	 * @see com.ldl.dao.LdlArticleDao#selectAll(int, int)
	 */
	@Override
	public List<LdlArticle> selectAll(int index, int len) throws SQLException{
		String sql = "select * from ldl_article limit "+index+","+len;
		List<LdlArticle> list = new ArrayList<LdlArticle>();
		try(
				Connection conn = DBHelper.getConn();
				PreparedStatement ps = conn.prepareStatement(sql);
				ResultSet res = ps.executeQuery();
			) {
			while(res.next()){
				SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
				LdlArticle article = new LdlArticle();
				article.setArticleId(res.getLong("ARTICLE_ID"));
				article.setArticleTitle(res.getString("ARTICLE_TITLE"));
				article.setArticleWorker(res.getString("ARTICLE_WORKER"));
				article.setArticleTime(sd.format(res.getObject("ARTICLE_TIME")));
				list.add(article);
			}
			return list;
		} 
	}

}
